package org.com.cis.cf.main;

import java.io.FileNotFoundException;

import org.com.cis.cf.BPRMF;
import org.com.cis.cf.LBDMF;
import org.com.cis.cf.ListMF;
import org.com.cis.cf.PMF;
import org.com.cis.cf.PPMF;
import org.com.cis.cf.PopMF;
import org.com.cis.cf.RandMF;


public class Main {
	
	static void runPmf(String args[]) throws FileNotFoundException
	{
		if(args.length != 9) {
			System.out.println("Usage: method trainPath testPath userNumber itemNumber featureNumber batch learnRate lambda");
			System.exit(2);
		}
		PMF pmf = new PMF();
		
		trainPath = args[1];
		testPath  = args[2];
		
		userNumber = Integer.parseInt(args[3]);
		itemNumber = Integer.parseInt(args[4]);
		featureNumber = Integer.parseInt(args[5]);
		
		batch = Integer.parseInt(args[6]);
		learnRate = Double.parseDouble(args[7]);
		lambda = Double.parseDouble(args[8]);

		pmf.initMolde(userNumber, itemNumber, featureNumber, learnRate, lambda, batch);
		pmf.readData(trainPath, testPath);
		pmf.runModel();
	}

	static void runBprmf(String args[]) throws FileNotFoundException
	{
		if(args.length != 9) {
			System.out.println("Usage: method trainPath testPath userNumber itemNumber featureNumber batch learnRate lambda");
			System.exit(2);
		}
		BPRMF bprmf = new BPRMF();
		
		trainPath = args[1];
		testPath  = args[2];
		
		userNumber = Integer.parseInt(args[3]);
		itemNumber = Integer.parseInt(args[4]);
		featureNumber = Integer.parseInt(args[5]);
		
		batch = Integer.parseInt(args[6]);
		learnRate = Double.parseDouble(args[7]);
		lambda = Double.parseDouble(args[8]);

		bprmf.initMolde(userNumber, itemNumber, featureNumber, learnRate, lambda, batch);
		bprmf.readData(trainPath, testPath);
		bprmf.runModel();
	}
	

	static void runRandmf(String args[]) throws FileNotFoundException
	{
		if(args.length != 9) {
			System.out.println("Usage: method trainPath testPath userNumber itemNumber featureNumber batch learnRate lambda");
			System.exit(2);
		}
		RandMF randmf = new RandMF();
		
		trainPath = args[1];
		testPath  = args[2];
		
		userNumber = Integer.parseInt(args[3]);
		itemNumber = Integer.parseInt(args[4]);
		featureNumber = Integer.parseInt(args[5]);
		
		batch = Integer.parseInt(args[6]);
		learnRate = Double.parseDouble(args[7]);
		lambda = Double.parseDouble(args[8]);

		randmf.initMolde(userNumber, itemNumber, featureNumber, learnRate, lambda, batch);
		randmf.readData(trainPath, testPath);
		randmf.runModel();
	}
	
	static void runPpmf(String args[]) throws FileNotFoundException
	{
		if(args.length != 9) {
			System.out.println("Usage: method trainPath testPath userNumber itemNumber featureNumber batch learnRate lambda");
			System.exit(2);
		}
		PPMF ppmf = new PPMF();
		
		trainPath = args[1];
		testPath  = args[2];
		
		userNumber = Integer.parseInt(args[3]);
		itemNumber = Integer.parseInt(args[4]);
		featureNumber = Integer.parseInt(args[5]);
		
		batch = Integer.parseInt(args[6]);
		learnRate = Double.parseDouble(args[7]);
		lambda = Double.parseDouble(args[8]);

		ppmf.initMolde(userNumber, itemNumber, featureNumber, learnRate, lambda, batch);
		ppmf.readData(trainPath, testPath);
		ppmf.runModel();
	}
	
	static void runListmf(String args[]) throws FileNotFoundException
	{
		if(args.length != 9) {
			System.out.println("Usage: method trainPath testPath userNumber itemNumber featureNumber batch learnRate lambda");
			System.exit(2);
		}
		ListMF listmf = new ListMF();
		
		trainPath = args[1];
		testPath  = args[2];
		
		userNumber = Integer.parseInt(args[3]);
		itemNumber = Integer.parseInt(args[4]);
		featureNumber = Integer.parseInt(args[5]);
		
		batch = Integer.parseInt(args[6]);
		learnRate = Double.parseDouble(args[7]);
		lambda = Double.parseDouble(args[8]);

		listmf.initMolde(userNumber, itemNumber, featureNumber, learnRate, lambda, batch);
		listmf.readData(trainPath, testPath);
		listmf.runModel();
	}
	
	static void runLbdmf(String args[]) throws FileNotFoundException
	{
		if(args.length != 10) {
			System.out.println("Usage: method trainPath testPath userNumber itemNumber featureNumber batch learnRate lambda momentum");
			System.exit(2);
		}
		LBDMF lbdmf = new LBDMF();
		
		trainPath = args[1];
		testPath  = args[2];
		
		userNumber = Integer.parseInt(args[3]);
		itemNumber = Integer.parseInt(args[4]);
		featureNumber = Integer.parseInt(args[5]);
		
		batch = Integer.parseInt(args[6]);
		learnRate = Double.parseDouble(args[7]);
		lambda = Double.parseDouble(args[8]);
		
		double momentum = Double.parseDouble(args[9]);

		lbdmf.initMolde(userNumber, itemNumber, featureNumber, learnRate, lambda, batch);
		lbdmf.readData(trainPath, testPath);
		lbdmf.runModel(momentum);
	}
	
	static void runPopmf(String args[]) throws FileNotFoundException
	{
		if(args.length != 9) {
			System.out.println("Usage: method trainPath testPath userNumber itemNumber featureNumber batch learnRate lambda");
			System.exit(2);
		}
		PopMF popmf = new PopMF();
		
		trainPath = args[1];
		testPath  = args[2];
		
		userNumber = Integer.parseInt(args[3]);
		itemNumber = Integer.parseInt(args[4]);
		featureNumber = Integer.parseInt(args[5]);
		
		batch = Integer.parseInt(args[6]);
		learnRate = Double.parseDouble(args[7]);
		lambda = Double.parseDouble(args[8]);

		popmf.initMolde(userNumber, itemNumber, featureNumber, learnRate, lambda, batch);
		popmf.readData(trainPath, testPath);
		popmf.runModel();
	}
	
	
	public static void main(String args[]) throws FileNotFoundException
	{
		if(args.length < 1) {
			System.out.println("please input parameters");
			System.out.println("avaliable method: pmf ppmf listmf bprmf lbdmf pop rand");
			System.exit(2);
		}
		
		method = args[0];
		
		if (method.equals("pmf")){
			runPmf(args);
		} else if (method.equals("bprmf")) {
			runBprmf(args);
		} else if (method.equals("ppmf")) {
			runPpmf(args);
		} else if (method.equals("listmf")) {
			runListmf(args);
		} else if (method.equals("lbdmf")) {
			runLbdmf(args);
		} else if (method.equals("rand")){
			runRandmf(args);
		} else if (method.equals("pop")){
			runPopmf(args);
		} else {
			System.out.println("unsupprted method " + method);
			System.exit(2);
		}
	}
	
	static String method;
	
	static String trainPath;
	static String testPath;
	
	static int userNumber;
	static int itemNumber;
	static int featureNumber;
	static int batch;
	static double learnRate;
	static double lambda;
}
